/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __frhash_make_key.c                                */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/18 by geyh                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"

#include "frstat_module.h"


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

int __frhash_make_key(u_short us_proto, int i_l7_proto
        , char *p_key, unsigned int ui_key_size);

static void __case1(void)
{
    int i_ret = 0;
    u_short us_proto = IPPROTO_TCP;
    int i_l7_proto = 1433;
    char *p_key = NULL;
    unsigned int ui_key_size = 0;

    i_ret = __frhash_make_key(us_proto, i_l7_proto, p_key, ui_key_size);

    CU_ASSERT_EQUAL(i_ret,0);

    return;
}

static void __case2(void)
{
    int i_ret = 0;
    u_short us_proto = IPPROTO_TCP;
    int i_l7_proto = 1433;
    char *p_key = NULL;
    unsigned int ui_key_size = 6;

    p_key = (char *)frmalloc(ui_key_size);
    memset(p_key, 0x00, ui_key_size);

    i_ret = __frhash_make_key(us_proto, i_l7_proto, p_key, ui_key_size);

    CU_ASSERT_EQUAL(i_ret,0);

    frfree(p_key);
    return;
}

static void __case3(void)
{
    int i_ret = 0;
    u_short us_proto = IPPROTO_TCP;
    int i_l7_proto = 1433;
    char *p_key = NULL;
    unsigned int ui_key_size = 7;

    p_key = (char *)frmalloc(ui_key_size);
    memset(p_key, 0x00, ui_key_size);

    i_ret = __frhash_make_key(us_proto, i_l7_proto, p_key, ui_key_size);

    CU_ASSERT_NOT_EQUAL(i_ret,0);

    frfree(p_key);
    return;
}


int add_suite___frhash_make_key(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frstat_module __frhash_make_key()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
//    CU_add_test(pSuite, "case4", __case4);

    return FR_SUCC;
}
